<template>
  <div class="app-container">
    <!-- 顶部搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" v-show="showSearch" label-width="68px">
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="出库人" prop="ckName">
            <el-input
              v-model="queryParams.ckName"
              placeholder="请输入出库人"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="物资名称" prop="wzName">
            <el-input
              v-model="queryParams.wzName"
              placeholder="请输入物资名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="物资分类" prop="wzFl">
            <el-input
              v-model="queryParams.wzFl"
              placeholder="请输入物资分类"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="物资规格" prop="wzGg">
            <el-input
              v-model="queryParams.wzGg"
              placeholder="请输入物资规格"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="物资专业" prop="wzZy">
            <el-input
              v-model="queryParams.wzZy"
              placeholder="请输入物资专业"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="领用人" prop="lyName">
            <el-input
              v-model="queryParams.lyName"
              placeholder="请输入领用人"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <!-- 顶部按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出Excel
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格 -->
    <el-table height="300" class="fixedTableTwo" @row-click="clickRow" ref="table" highlight-current-row
              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
              v-loading="loading" :data="bfCkList">
      <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>
      <el-table-column show-overflow-tooltip label="出库方式" align="center" prop="ckFs">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wzgl_ckfs" :value="scope.row.ckFs"/>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="出库日期" align="center" prop="ckTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ckTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="出库人" align="center" prop="ckName"/>
      <el-table-column show-overflow-tooltip label="物资名称" align="center" prop="wzName"/>
      <el-table-column show-overflow-tooltip label="物资单位" align="center" prop="wzDw"/>
      <el-table-column show-overflow-tooltip label="物资分类" align="center" prop="wzFl"/>
      <el-table-column show-overflow-tooltip label="物资规格" align="center" prop="wzGg"/>
      <el-table-column show-overflow-tooltip label="物资专业" align="center" prop="wzZy"/>
      <el-table-column show-overflow-tooltip label="领用人" align="center" prop="lyName"/>
      <el-table-column show-overflow-tooltip label="备注" align="center" prop="bz"/>
      <el-table-column show-overflow-tooltip label="单价" align="center" prop="dj"/>
      <el-table-column show-overflow-tooltip label="出库数量" align="center" prop="ckSl"/>
      <el-table-column show-overflow-tooltip label="合计金额" align="center" prop="hjJe"/>
    </el-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {selectBfCkList} from "@/api/wzgl/bfckcx";

export default {
  name: "Bfckcx",
  dicts: ['wzgl_ckfs'],
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ckName: null, //出库人
        wzName: null, //物资名称
        wzFl: null, //物资分类
        wzGg: null, //物资规格
        wzZy: null, //物资专业
        lyName: null, //领用人
      },
      // 遮罩层
      loading: true,
      //报废出库查询表格数据
      bfCkList: [],
      // 总条数
      total: 0,

    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    getList() {
      this.loading = true;
      selectBfCkList(this.queryParams).then(res => {
        this.bfCkList = res.rows
        this.total = res.total;
        this.loading = false;
      })
    },
    //点击行 获取行
    clickRow(row) {
      this.selectedRow = row; // 更新选中的行
      const table = this.$refs.table;
      const selectedRows = table.selection;

      // 否则取消之前选中的行，并选中当前点击的行
      selectedRows.forEach(selectedRow => {
        table.toggleRowSelection(selectedRow);
      });
      table.toggleRowSelection(row);
    },
    /** 自定义序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if ((pageNum !== -1 && pageNum !== 0)) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return (index + 1)
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wzgl/bfckcx/export', {
        ...this.queryParams
      }, `报废出库列表_${new Date().getTime()}.xlsx`)
    },

  }
}
</script>

<style scoped>

</style>
